function AllowAdminNoclip(ply)
	if (ply:IsAdmin() or ply:IsSuperAdmin()) and server_settings.Bool( "SB_AdminSpaceNoclip" ) then return true end
	if ply:IsSuperAdmin() and server_settings.Bool( "SB_SuperAdminSpaceNoclip" ) then return true end
	return false
end



function GM:PlayerNoClip( pl, on )
	--no clip allowed in singleplayer, on planets, is turning off noclip, is admin, or SB_PlanetNoClipOnly is off
	--TODO, allow a little margin away from planet for before disabing noclip so players do get stuck in the walls around the edges of the planets
	if SinglePlayer() or (server_settings.Bool("SB_NoClip") and server_settings.Bool("sbox_noclip") and (pl.planet or AllowAdminNoclip(pl) or not server_settings.Bool("SB_PlanetNoClipOnly"))) then return true end
	return false
end



function GM:PlayerSay( ply, txt )
	//self.BaseClass:PlayerSay( ply, txt )

--This is where things that all players can access via chat hooks are

	if (string.sub(txt, 1, 10 ) == "!asteroids") then
		spawnAsteroid(5)
		return ""
	end

	local x = math.random(1,12)
	if (string.sub(txt, 1,8 ) == "/join TD") then
		ply:SetTeam(All_Teams[1].Index);
		ply:ChatPrint("You have joined the Terran Dominion\n\n     Glory to the Dominion!")
		ply:StripWeapons()  
		ply:ShouldDropWeapon(false)
		ply.WeaponOverride=true
		ply:RemoveAmmo("AR2")
		ply:RemoveAmmo("smg1")
		ply:RemoveAmmo("427")
        ply:Give( "weapon_physgun" )		
		ply:Give( "weapon_ar2" )
		ply:GiveAmmo(100,"AR2")
		ply:GiveAmmo(3,"AR2AltFire")
        ply:Give( "gmod_tool" )
		ply.WeaponOverride=false
		ply.maxAmmo = 120
		ply:UnSpectate()
		local x = math.random(1,12)
		if(x<=4) then
			ply:SetModel("models/player/urbantrenchcoat.mdl")
		
		elseif(x<=8) then
			ply:SetModel("models/Europee_Normal1.mdl")
				
		elseif(x<=12) then
			ply:SetModel("models/Europee_orange1.mdl")
		end
			ply:SetColor(255, 255, 255, 255)
		return "";	
	elseif (string.sub(txt, 1,8 ) == "/join XE") then
		ply:SetTeam(All_Teams[2].Index);
		ply:ChatPrint( "Welcome Brother, to the Xenophine Empire\n\nWe are as one soul, unified in victory!")
		ply:StripWeapons()  
		ply:ShouldDropWeapon(false)
		ply.WeaponOverride=true
		ply:RemoveAmmo("AR2")
		ply:RemoveAmmo("smg1")
		ply:RemoveAmmo("427")
		ply:Give( "weapon_physgun" )
        ply:Give( "weapon_staff" )
		ply:Give( "emolate" )
        ply:Give( "gmod_tool" )
		ply.WeaponOverride=false
		ply.maxAmmo = 100
		ply:UnSpectate()
		if(x<4) then
			ply:SetModel("models/player/headcrab.mdl")
		
		elseif(x<=8) then
			ply:SetModel("models/player/hl2/combine_zombie.mdl")
				
		elseif(x<=12) then
			ply:SetModel("models/player/headcrab.mdl")
		end
			ply:SetColor(255, 255, 255, 255)
		return "";	

		
	elseif (string.sub(txt, 1,8 ) == "/join AA") then
 		ply:SetTeam(All_Teams[3].Index);
		ply:ChatPrint("Hail, Arbiter!\n\nYour number joins us in The Duty");
		ply:UnSpectate()
		ply:RemoveAmmo("AR2")
		ply:RemoveAmmo("smg1")
		ply:RemoveAmmo("427")
		ply:StripWeapons()  
		ply:ShouldDropWeapon(false)
		ply.WeaponOverride=true
        ply:Give( "weapon_physgun" )
		ply:Give( "weapon_adminsidearm" )
		ply:Give( "shield_gun" )
		ply:Give( "gmod_tool" )
		ply:GiveAmmo(25, "smg1" )
		ply.WeaponOverride=false
			
		if(x<=4) then
			ply:SetModel("models/player/assassin.mdl")
		
		elseif(x<=8) then
			ply:SetModel("models/player/assassin.mdl")
		
		elseif(x<=12) then
			ply:SetModel("models/player/assassin.mdl")
		end
		ply:SetColor(255, 255, 255, 255)
		return "";	

	
		
	elseif (string.sub(txt, 1,5 ) == "/join" and string.sub(txt, 6,8 ) == "" ) then
		ply:ChatPrint("Select your Allegence!");
		ply:ConCommand("join")
		return "";	
		
		
	else return txt;
	end


--This Is where things that ONLY ADMINS can access via chat hooks are

	if not ply:IsAdmin() then return end
	if (string.sub(txt, 1, 10 ) == "!freespace") then
		self:RemoveSBProps()
		return "Space's props have been cleaned up";

	elseif (string.sub(txt, 1, 10 ) == "!freeworld") then
		self:RemoveSBProps(true);
		return "This worlds props have been cleaned up";

	else return txt;
	end
end



function GM:RemoveSBProps(world)
	for _, class in ipairs( self.affected ) do
		local stuff = ents.FindByClass( class )
		for _, ent in ipairs( stuff ) do
			if world and ent.planet then
				if not ent:IsPlayer() then
					local delay = (math.random(1, 500) / 100)
					ent:SetKeyValue("exploderadius","1")  
					ent:SetKeyValue("explodedamage","1")  
					ent:Fire("break","",tostring(delay)) 
					ent:Fire("kill","",tostring(delay + 1)) 
				end
			elseif not world and not ent.planet then
				if not ent:IsPlayer() then
					local delay = (math.random(1, 500) / 100)
					ent:SetKeyValue("exploderadius","100")  
					ent:SetKeyValue("explodedamage","10")  
					ent:Fire("break","",tostring(delay)) 
					ent:Fire("kill","",tostring(delay + 1)) 
				end
			end
		end
	end
end